package com.example.neteasemusic

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.viewbinding.ViewBinding
import com.example.lib_common_ui.bottombar.TabBarItem
import com.example.lib_data.base.activity.BaseActivity
import com.example.lib_data.bmob.BmobManager
import com.example.lib_data.bmob.MusicManager
import com.example.lib_data.bmob.UserManager
import com.example.login.LoginActivity
import com.example.neteasemusic.adapter.ViewPagerAdapter
import com.example.neteasemusic.databinding.ActivityMainBinding
import com.example.neteasemusic.fragments.CircleFragment
import com.example.neteasemusic.fragments.HomeFragment
import com.example.neteasemusic.fragments.MeFragment

class MainActivity : BaseActivity() {
    private val binding:ActivityMainBinding by lazy {
        mBinding as ActivityMainBinding
    }

    override fun getLayoutBinding(): ViewBinding? {
        return ActivityMainBinding.inflate(layoutInflater)
    }

    override fun initUI() {
        //检测是否已经有登录用户
        //UserManager.getInstance().logout()
        checkIsLogin()

        //加载音乐数据
        //loadMusics()

        //配置底部标签栏
        initBottomBar()

        //配置ViewPager2
        initViewPager()
    }

    private fun checkIsLogin(){
        if(UserManager.getInstance().isLogin()) return  //登录过了
        //进入到登录模块完成登录
        val intent = Intent(this, LoginActivity::class.java)
        startActivity(intent)
    }
    private fun loadMusics(){
        MusicManager.instance.loadMusics(
            onStart = {},
            callBack = {}
        )
    }
    private fun initBottomBar(){
        binding.bottomTabBar.setupWithBarItems(
            listOf(
                TabBarItem(R.drawable.tab_home,R.drawable.tab_selected_home,"发现"),
                TabBarItem(R.drawable.tab_circle,R.drawable.tab_selected_circle,"动态"),
                TabBarItem(R.drawable.tab_me,R.drawable.tab_selected_me,"我的")
            )
        ){
            //某个Item被点击的回调
            binding.viewPager.setCurrentItem(it,false)
        }
    }
    private fun initViewPager(){
        //配置ViewPager的适配器adapter
        binding.viewPager.adapter = ViewPagerAdapter(
            listOf(HomeFragment(),CircleFragment(),MeFragment()),
            supportFragmentManager,
            lifecycle
        )
        //禁止用户滑动
        binding.viewPager.isUserInputEnabled = false
    }
}


















